<?php
namespace app\wypadmin\controller;
use think\Controller;
use think\Request;
use think\Session;

class Login extends Controller
{
	public function index(){
		

		return $this->fetch();
	}

	public function login(){
		$request = Request::instance();

		$username 	= $request->post('username');
		$pwd 		= md5($request->post('pwd'));

		$users = Model('User/User');

		$res = $users->where(['username'=>$username])->find();

		if ($res && ($pwd == $res['pwd'])) {
			Session::set('uid',$res['id']);
			Session::set('username',$res['username']);
			$this->redirect('Index/index');
		}else{
			echo '<script>alert(\'操作员姓名或密码不正确\');history.back();</script>';
			return;
		}
	}

	public function logout(){
		Session::delete('uid');
		Session::delete('username');
        $this->redirect(url('Login/index'));
	}
}